package cn.wolfcode.producer._02_mode;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.util.concurrent.CountDownLatch;

/**
 * 一次性发送信息:一次性将信息全部发送,不关心发送的结果,直接到broker
 */
public class Producer2 {
    public static void main(String[] args) throws Exception {
        //1.创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("wolfcode_producer");
        //2.设置nameSrv地址
        producer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动生产者
        producer.start();
        //发送一百条消息
        for (int i=0; i < 100; i++) {
            //4.设置发送的消息(默认是同步消息)
            Message message = new Message("02_mode","你好啊rocketMQ".getBytes());
            //5.生产者对象发送消息
           producer.sendOneway(message);
           //当都发送完的时候,在关闭连接
        }
        //6.关闭连接
        producer.shutdown();
    }
}
